﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace sXNAke
{
    class Snake
    {
        Texture2D texture;
        Vector2 position;
         public Rectangle collisionRect;

        GameWindow Window;

        public Snake(Texture2D texture, GameWindow Window)
        {
            this.texture = texture;
            this.Window = Window;
        }

        public void Update(KeyboardState keyboardState)
        {
            if (keyboardState.IsKeyDown(Keys.Right))
            {
                position.X += 5;
            }
            else
                if (keyboardState.IsKeyDown(Keys.Left))
                {
                    position.X -= 5;
                }
                else
                    if (keyboardState.IsKeyDown(Keys.Down))
                    {
                        position.Y += 5;
                    }
                    else
                        if (keyboardState.IsKeyDown(Keys.Up))
                        {
                            position.Y -= 5;
                        }

            if (position.X >= Window.ClientBounds.Width - texture.Width)
            {
                position.X = Window.ClientBounds.Width - texture.Width;
            }
            if (position.X <= 0)
            {
                position.X = 0;
            }
            if (position.Y <= 0)
            {
                position.Y = 0;
            }
            if (position.Y >= Window.ClientBounds.Height - texture.Height)
            {
                position.Y = Window.ClientBounds.Height - texture.Height;
            }

            collisionRect = new Rectangle((int)position.X, (int)position.Y, texture.Width, texture.Height);

        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(texture, position, Color.White);
        }
    }
}
